package com.lvyq.myplayer.model.ranking

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.lvyq.myplayer.net.api.indexDailyPlayApiService
import kotlinx.coroutines.launch

/**
 * 文件描述：RankingItemModel
 * 作者：lvyq
 * 创建时间：2025-06-03
 * 修改时间：2025-06-03
 */
class RankingItemModel: ViewModel() {
    private val _data = MutableLiveData<RankingItemBean>()
    val data: LiveData<RankingItemBean> = _data

    fun list(rankingId:Int){
        viewModelScope.launch {
            try {
                // 使用协程发起网络请求
                val response = indexDailyPlayApiService.rankingItemList(rankingId)
                if (response.isSuccessful) {
                    _data.value = response.body()

                } else {
                    // 处理错误
                    Log.e("RankingItemModel", "Error: ${response.code()}")
                }
            } catch (e: Exception) {
                // 处理异常
                Log.e("RankingItemModel", "Exception: ${e.message}")
            }
        }
        }
    }
